import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'


Vue.config.productionTip = false

// 初始化跨平台的工具类。
import SDK from 'sxran-tool-sdk/Index'
import XeBase from 'sxran-tool-core/lib/XeBase';
import UniAppWebSocket from "sxran-tool-uniapp/lib/UniAppWebSocket";
import UniAppBroadcastChannel from "sxran-tool-uniapp/lib/UniAppBroadcastChannel";
import UniAppStorage from "sxran-tool-uniapp/lib/UniAppStorage";

const sdk = new SDK();
const xeBase = new XeBase();
const uniAppWebSocket = new UniAppWebSocket();
const uniAppBroadcastChannel = new UniAppBroadcastChannel();
const uniAppStorage = new UniAppStorage();

sdk.setApi(SDK.BASE_NAME,xeBase);
sdk.setApi(SDK.WEBSOCKET_NAME,uniAppWebSocket);
sdk.setApi(SDK.BROADCAST_CHANNEL_NAME,uniAppBroadcastChannel);
sdk.setApi(SDK.STORAGE_NAME,uniAppStorage);
Vue.prototype.$sxran = sdk;

// 获得ws的内容。
import ws from 'lib/websocket'
ws.copySdk(sdk);
Vue.prototype.$ws = ws;
////////////////////////
// 封装一下特别的方法内容。
////////////////////////

// 初始化设置tabbar角标未读数。
// 注意：在非tabbar页面无法设置 badge
 function initUnreadCount () {
  // 会话设置
  // 系统通知设置
  let unreadCount = ws.state.notification.unreadCount({excludeType: [46]});
  if (unreadCount === 0) {
      uni.removeTabBarBadge({
          index: 1,
          complete: (e) => {
              console.log(e)
          }
      })
  } else {
      uni.setTabBarBadge({
          index: 1,
          text: unreadCount + '',
          complete: (e) => {
              console.log(e)
          }
      })
  }
}
Vue.prototype.initUnreadCount = initUnreadCount;
// 设置状态栏监听。
ws.setMonitor([26,-28],(res)=>{
    // initUnreadCount(); // 系统通知消息提示。
});

// 接收聊天消息的处理
ws.setMonitor([11],(res)=>{
    switch (res.data.msgType) {
        case 7 :
        case 8 :
            uni.navigateTo({
                url: res.data.content
            })
            break;
        default :
            break;
    }
});


App.mpType = 'app'
const app = new Vue({
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif